package client;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;

import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;

public class Test {
	public static void main(String[] args) throws IOException {
		ServerSocket server = new ServerSocket(8887);
		Socket sk = server.accept();
		BufferedReader reader = new BufferedReader(new InputStreamReader(sk.getInputStream()));
		OutputStream out = sk.getOutputStream();
		
		String line = null;
		while((line=reader.readLine()).trim().length() != 0){
			System.out.println(line);
		}
		System.out.println("header end...");
		
		Document dom = new Document();
		Element root = new Element("html");
		Element body = new Element("body");
		Element a1 = new Element("a");
		a1.setText("open");
		a1.setAttribute("href", "http://localhost:8887/open");
		body.addContent(a1);
		root.addContent(body);
		dom.setRootElement(root);
		XMLOutputter ot = new XMLOutputter();
		
		out.write("HTTP/1.1 200 OK\r\n\r\n".getBytes());
		ot.output(root, out);
		
		out.close();
		reader.close();
		out.close();
		server.close();
	}
}
